#!/usr/bin/env node

const Koa = require('koa');
const Bodyparser = require('koa-bodyparser');
const loadRouters = require('require-directory');
const logger = require('koa-logger');
const koaBody = require('koa-body')
const app = new Koa();

//设置跨域资源请求的问题
app.use(async (ctx,next) => {
  ctx.set('Access-Control-Allow-Origin', '*');
  ctx.set('Access-Control-Allow-Headers','Content-Type, Content-Length, Authorization, Accept, X-Requested-With,yourHeaderFeild'
    );
  ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE');
  if(ctx.method == 'OPTIONS'){
    ctx.body = 200;
  }else{
    await next();  }
})
app.use(logger());
app.use(koaBody({
  multipart:true
}))


loadRouters(module,'./routes',{visit:(r) => {
  app.use(r.routes());
}})


app.listen(2002);